package com.jiaai.shop;


import com.jiaai.shop.jpush.JPushUtils;
import com.jiaai.shop.util.IdWorkUtil;
import com.jiaai.shop.util.ThreadPoolProxy;
import com.jiaai.shop.util.redis.RedisUtil;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableAutoConfiguration
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

//	@Bean("cacheManager")
//	public CacheManager getCacheManager(){
//		CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
//				.withCache("preConfigured",
//						CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
//								ResourcePoolsBuilder.heap(100))
//								.build())
//				.build(true);
//		return  cacheManager;
//	}

	/**
	 * 配制id生成器
	 * @param redisUtil
	 * @return
	 */
	@Bean
	@ConditionalOnMissingBean(IdWorkUtil.class)//容器中如果没有RedisClient这个类,那么自动配置这个IdWorkUtil
	public IdWorkUtil idWorkUtil(@Qualifier("rdisUtil")RedisUtil redisUtil) {
		IdWorkUtil workUtil=new IdWorkUtil(redisUtil,23);
		return workUtil;
	}

	@Bean
	@ConditionalOnMissingBean(ThreadPoolProxy.class)
	public ThreadPoolProxy threadPoolProxy(){
		return  new ThreadPoolProxy(60,100,10000);
	}

	@Bean
	@ConditionalOnMissingBean(JPushUtils.class)
	public JPushUtils jPushUtils(@Qualifier("threadPoolProxy")ThreadPoolProxy threadPoolProxy){
		return  new JPushUtils("b6ce7fa38263ba91a7fc96ef","2397a2d62af0b16f60276956",threadPoolProxy);
	}

}
